package com.moshang.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moshang.blog.entity.Rescource;
import com.moshang.blog.mapper.RescourceMapper;
import com.moshang.blog.service.SysRescourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: blog
 * @description: 系统资源实现类
 * @author: xieweiwei
 * @create: 2018-09-30 16:57
 **/
@Service("rescourceService")
@Transactional( rollbackFor = Exception.class)
public class SysRescourceServiceImpl extends ServiceImpl<RescourceMapper,Rescource> implements SysRescourceService {
    @Resource
    private RescourceMapper rescourceMapper;
    @Override
    public Rescource selectByCondition(String hash,String source) {

        QueryWrapper<Rescource> param=new QueryWrapper<>();

        param.eq("hash",hash);
        param.eq("source",source);
       Rescource rescource=rescourceMapper.selectOne(param);
        if (rescource!=null){
            return rescource;
        }
        return null;
    }

    @Override
    public Rescource insertRescource(Rescource rescource) {
        baseMapper.insert(rescource);
        return rescource;
    }

    @Override
    public List<Rescource> findByLately() {
        QueryWrapper<Rescource> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("is_activited",0);
        queryWrapper.orderBy(true,false,"create_time").last("limit 1,5");
        List<Rescource> list=baseMapper.selectList(queryWrapper);
        return list;
    }
}
